<template>
  <div>
    <el-dialog :title="title" :close-on-click-modal="false" :visible="true" width="80%" @close="handleClose">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="名称：" required>
          <el-input v-model="form.name" placeholder="请输入名称"></el-input>
        </el-form-item>
        <el-form-item label="讲师：" required>
          <el-input v-model="form.speaker" placeholder="请输入讲师"></el-input>
        </el-form-item>
      </el-form>



      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="handleConmit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getCourseQuestionInfo } from "@/api/course";
export default {
  props:{
    title:{
      type:String,
      default:'添加习题集'
    },
    type:{
      type:String,
      default:'add'
    },
    id:{
      type:String | Number
    }
  },
  data() {
    return {
      form: {
        name: '',
        speaker:''
      }

    }
  },
  created() {
    if(this.type === 'edit'){
      this.getInfo();
    }
  },
  methods: {
    async getInfo(){
      let res = await getCourseQuestionInfo({
        id:this.id
      })
      this.form.name = res.data.name;
      this.form.speaker = res.data.speaker;

    },
    handleClose() {
      this.$emit('close')
    },
    handleConmit(){
      if (this.form.name === '') {
        this.$message({
          message: '请输入习题集名称！',
          type: 'warning'
        });
        return false;
      }
      if (this.form.speaker === '') {
        this.$message({
          message: '请输入讲师名称！',
          type: 'warning'
        });
        return false;
      }
      this.$emit('conmit',this.form)
    }
  },
}
</script>
<style lang="scss" scoped>

</style>
